import {UPDATE_ROLE, UPDATE_TOKEN} from '../reducersTypes'
// const token = localStorage.getItem('token')
const initState = {
  role: '',
  token: '',
  info: {
    name: '',
    department: ''
  }
}

export default (state = initState, action) => {
  const newState = {...state}
  switch (action.type) {
    case UPDATE_TOKEN:
      newState.token = action.payload
      window.localStorage.setItem('token', action.payload)
      break;
    case UPDATE_ROLE:
      newState.role = action.payload.roles[0]
      newState.info = {
        name: action.payload.name,
        department: action.payload.department
      }
      break;
  
    default:
      break;
  }
  return newState
}